package Pieces;

import logic.BeamDirection;
import logic.Piece;
import logic.Team;

public class Pyramid implements Piece{
	
	private Team owner;
	private short direction;
	private short resetDirection;
	
	public Pyramid (Team owner, short direction){
		resetDirection = direction;
		this.direction = direction;
		this.owner = owner;
	}
	
	public Pyramid (Team owner){
		this(owner, (short) 0);
	}
	
	@Override
	public Team getTeam() {
		return owner;
	}

	@Override
	public BeamDirection reflexBeam(BeamDirection incidence) {
		switch (direction) {
		case 0:
			if(incidence==BeamDirection.UP)	return BeamDirection.RIGHT;
			if(incidence==BeamDirection.RIGHT) return BeamDirection.UP;
			return BeamDirection.NODIRECTION;
		case 1:
			if(incidence==BeamDirection.UP) return BeamDirection.LEFT;
			if(incidence==BeamDirection.LEFT) return BeamDirection.UP;
			return BeamDirection.NODIRECTION;
		case 2:
			if(incidence==BeamDirection.DOWN) return BeamDirection.LEFT;
			if(incidence==BeamDirection.LEFT) return BeamDirection.DOWN;
			return BeamDirection.NODIRECTION;
		case 3:
			if(incidence==BeamDirection.DOWN) return BeamDirection.RIGHT;
			if(incidence==BeamDirection.RIGHT) return BeamDirection.DOWN;
			return BeamDirection.NODIRECTION;
		}
		return BeamDirection.NODIRECTION;
	}

	@Override
	public void resetPiece() {
			this.direction = resetDirection;
	}

	@Override
	public void rotateLeft() {
		direction = (short) ((direction+1)%4);
	}

	@Override
	public void rotateRigth() {
		direction--;
		if(direction<0) direction = 3;
	}
	
	public short getOrientation() {
		return direction;
	}
	
	public String toString(){
		return "Pyramid "+owner+" "+direction;
	}

}
